package com.zabra.zl.ui.updatepwd.presenter;

import com.zabra.zl.base.BasePresenter;
import com.zabra.zl.data.SimpleBean;
import com.zabra.zl.net.RxScheduler;
import com.zabra.zl.ui.updatepwd.contract.UpdatePwdContract;
import com.zabra.zl.ui.updatepwd.model.UpdatePwdModel;

import io.reactivex.functions.Consumer;
import okhttp3.RequestBody;

public class UpdatePwdPresenter extends BasePresenter<UpdatePwdContract.View> implements UpdatePwdContract.Presenter {
    private UpdatePwdContract.Model model;

    public UpdatePwdPresenter() {
        model=new UpdatePwdModel();
    }

    @Override
    public void getData(RequestBody body) {
        if (!isViewAttached()) {
            return;
        }
        mView.showLoading();
        model.getData(body).compose(RxScheduler.Flo_io_main())
                .as(mView.bindAutoDispose())
                .subscribe(new Consumer<SimpleBean>() {
                    @Override
                    public void accept(SimpleBean bean) throws Exception {
                        mView.hideLoading();
                        mView.onSuccess(bean);
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        mView.hideLoading();
                        mView.onError(throwable);
                    }
                });
    }
}
